package com.photoeditor.demo.model.image.collage.templet;

public class Point {
    public float x;
    public float y;

    public Point(){

    }

    public Point(float x, float y){
        this.x = x;
        this.y = y;
    }

    public Point(Point other){
        this.x = other.x;
        this.y = other.y;
    }

    public void set(Point other){
        this.x = other.x;
        this.y = other.y;
    }

    public void set(float otherX, float otherY){
        this.x = otherX;
        this.y = otherY;
    }

    public void offset(float dx, float dy){
        x += dx;
        y += dy;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof Point)) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        Point that = (Point) obj;
        return this.x == that.x && this.y == that.y;
    }

    public boolean approximationEquals(Object obj) {
        if (obj == null || !(obj instanceof Point)) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        Point that = (Point) obj;
        return Math.abs(this.x - that.x) < CollagePoints.ADMISSIBLE_ERROR &&
                Math.abs(this.y - that.y) < CollagePoints.ADMISSIBLE_ERROR;
    }

    @Override
    public String toString(){
        return "x = " + x + "  y = " + y;
    }

    @Override
    protected Point clone() {
        return new Point(x,y);
    }
}
